//
//  TravelDetaileTableViewCell.m
//  旅游咨询
//
//  Created by 徐斌 on 15/4/14.
//  Copyright (c) 2015年 xubin. All rights reserved.
//

#import "TravelDetaileTableViewCell.h"
#define MAIN     ([[UIScreen mainScreen]bounds])


@implementation TravelDetaileTableViewCell

- (void)dealloc
{
    [_myImageVIew release];
    [_tLabel release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatSubView];
    }
    return self;
}

- (void)creatSubView
{
//   NSLog(@"%@---", self.detailModel.text);
    self.myImageVIew = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, WidthZ *0.946667, 200)];
 
//    [self.contentView addSubview:self.myImageVIew];
    self.myImageVIew.backgroundColor = [UIColor redColor];
    self.backgroundColor = [UIColor whiteColor];
    self.tLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 220, WidthZ *0.946667, 100)];
    [self.contentView addSubview:self.tLabel];
//    self.tLabel.backgroundColor = [UIColor brownColor];
    self.tLabel.numberOfLines = 0;
    [_myImageVIew release];
    [_tLabel release];
   
    
    
    
}

- (void)setDetailModel:(TravelNotesDetailModel *)detailModel
{
    
    NSURL *url = [NSURL URLWithString:detailModel.photo];

//    [self.tLabel sizeToFit];
    self.tLabel.font = [UIFont systemFontOfSize:15];
    
    self.placeImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
    self.placeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    self.placeLabel.font = [UIFont systemFontOfSize:20];
    self.placeLabel.text = @"加载中";
    
    
    
    [self.myImageVIew sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"gray.png"]];
    
  
    
//    ![[detailModel.photo_info class] isKindOfClass:[NSNull class]]
    if ([detailModel.photo_info class] != [NSNull class]){
    NSString *w = [detailModel.photo_info objectForKey:@"w"];
    NSString *h = [detailModel.photo_info objectForKey:@"h"];
    
    CGRect imageFram = CGRectMake(WidthZ * 0.02667, HeighZ * 0.015, WidthZ *0.946667, 2);
    imageFram.size.height = [h floatValue] / ([w floatValue] / WidthZ *0.946667);
    self.myImageVIew.frame = imageFram;
        self.placeImage.frame = imageFram;
        self.placeLabel.center = CGPointMake(self.placeImage.frame.size.width / 2, self.placeImage.frame.size.height / 2);
    [self.contentView addSubview:self.myImageVIew];
    self.tLabel.frame = CGRectMake(WidthZ * 0.02667, self.myImageVIew.frame.size.height + 20, WidthZ *0.946667, 100);
    
        
        
//    NSLog(@"xiao imageview hei %f",self.imageView.frame.size.height);
    CGRect fram = self.tLabel.frame;
    fram.size.height = [[self class] getHeighContent:detailModel.text];
    self.tLabel.frame = fram;
//    [[self class] getHeighContent:detailModel.text];
        

        
        
    self.tLabel.text = detailModel.text;
    }
    else
    {
//        NSLog(@"wozoule ");
        self.myImageVIew.frame = CGRectMake(0, 0, 0, 0);
        self.tLabel.frame = CGRectMake(WidthZ * 0.02667, self.myImageVIew.frame.size.height + 20, WidthZ *0.946667, 100);
        CGRect fram = self.tLabel.frame;
        fram.size.height = [[self class] getHeighContent:detailModel.text];
        self.tLabel.frame = fram;
        //    [[self class] getHeighContent:detailModel.text];
        self.tLabel.text = detailModel.text;
        
        
    }
//    NSLog(@"labelHeight:%f", self.tLabel.frame.size.height);
}

+(CGFloat)getHeighContent:(NSString *)content
{
    CGSize size = CGSizeMake(WidthZ *0.946667, 2000);
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15] forKey:NSFontAttributeName];
    
    CGRect fram = [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return fram.size.height;
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
